
$(function () {
	//请求的这个controller只能回显名字
    $.ajax({
        url: "/doublesys/user/getCurrentUser.htm",
        cache: false,
        type: "post",
        dataType: "json",
        success: function (result) {
            var data = result.data;
            if (result.status == 0) {
                $("#editSysUser").formatForm(data,['password']);
                $("#userId").val(data.id);
                $("#password").val('');
                $("#name").val(data.name);
            } else {
                layer.msg(result.message, {icon: 2});
            }
        }
    });
    
    
  
    $('#editSysUserForm').validationEngine('attach', {
        validationEventTrigger : 'blur',
        promptPosition: 'inline',
        scroll: true,
        focusFirstField : true,
        onValidationComplete : function (form, valid) {
            if (valid){
                modifyUser();
            }
        }
    });
    
});


//修改个人资料
function modifyUser() {
	$.ajax({
        url: "/doublesys/user/updateUserById.htm",
        cache: false,
        type: "post",
        dataType: "json",
        data: $("#editSysUserForm").serialize(),
        success: function (result) {
            if (result.status == 0) {
                layer.msg(result.message, {icon: 1});
                location.href = '/doublesys/user/logout.htm';
                return;
            }
            layer.msg(result.message, {icon: 2});
        }
    });
}
